﻿


<?php
// 初始化页面
require_once "../init.php";



function add_bug($short_desc, $detail_desc, $to_whom)
{
	include "../init.php";	
	$str = "INSERT INTO tt_bugtrack(sdesc, ddesc, to_whom, report_time) values ('".$short_desc."','".$detail_desc."','".$to_whom."', NOW())";
	echo $str;
	
	$_SGLOBAL['db']->query($str);
	
	return;
}


// 当验证通过后，启动 session  
session_start();  


if (isset($_SESSION["admin"]) && $_SESSION["admin"] === true)  
{

	// $action = getgpc("action");
	// $uid = getgpc("id");
	//$_SGLOBAL['view']->assign("username",$_SESSION["user"]);
	$posts = $_POST;  
	if (!empty($posts))
	{
		// 清除一些空白符号  
		foreach ($posts as $key => $value)  
		{  
			$posts[$key] = trim($value);  
		}
		switch ($posts["type"])
		{
			case "login":
			{
				Header("Location: error.php");
				break;
			}
			case "bug":
			{
				add_bug($posts["sdesc"], $posts["ddesc"], $posts["to_whom"]);
				break;
			}
			default:
			{
				Header("Location: error.php");
				break;
			}
		}
	}
	$result = $_SGLOBAL['db']->fetch_all("SELECT * from tt_bugtrack");
	$_SGLOBAL['view']->assign('buglist', $result);
	$_SGLOBAL['view']->display('bugtrack_main.tpl');	
}
else
{
	// 表单提交后...  
	$posts = $_POST;  

	if (!empty($posts))
	{
 
		// 清除一些空白符号  
		foreach ($posts as $key => $value)  
		{  
			$posts[$key] = trim($value);  
		}  
		$password = $posts["pp"];  
		$username = $posts["uin"];
 
		if ($password == "123456" and $username == "raywill")  
		{  
			// 注册登陆成功的 admin 变量，并赋值 true  
			$_SESSION["admin"] = true;
			$_SESSION["user"] = $username;
			Header("Location: bugtrack.php");  
		}  
	}

	{
		$_SGLOBAL['view']->display('bugtrack_login.tpl');
		die("用户名密码错误");  
	}
}

?> 




























